#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main()
{
  close(1);
  int fd = open("log.txt", O_WRONLY);
  //int fd1 = open("log.txt1", O_RDONLY|O_CREAT, 0664);
	//int fd2 = open("log.txt2", O_RDONLY|O_CREAT, 0664);
	//int fd3 = open("log.txt3", O_RDONLY|O_CREAT, 0664);
	//int fd4 = open("log.txt4", O_RDONLY|O_CREAT, 0664);
	//int fd5 = open("log.txt5", O_RDONLY|O_CREAT, 0664);
  if (fd < 0){
    perror("open file fail");
    exit(-1);
  }
  //dup2(fd, 1);// 把指向标准输出流文件改成指向标识符为fd的文件
  //char buf[64] = {0};
  //scanf("%s", buf);
  const char* msg1 = "hello write\n";
  const char* msg2 = "hello printf\n";
  const char* msg3 = "hello fwrite\n";
  write(fd, msg1, strlen(msg1));
  printf(msg2);
  fwrite(msg3, strlen(msg3), 1, stdout);
  //printf("fd:%d, you can see me...\n", fd);
  //printf("%s\n", buf);
  fork();
  fflush(stdout);
  close(fd);
	//printf("fd1:%d\n", fd1);
	//printf("fd2:%d\n", fd2);
	//printf("fd3:%d\n", fd3);
	//printf("fd4:%d\n", fd4);
	//printf("fd5:%d\n", fd5);
  //close(fd1);
  //close(fd2);

	return 0;
}
